package com.ncloud.resman.mapper;

import com.alibaba.fastjson.JSONObject;
import com.ncloud.resman.entity.DeviceSwitch;
import com.ncloud.resman.entity.ExportSwitchInfo;

import java.util.List;

import org.apache.ibatis.annotations.*;

/**
 * Created by shiqiang on 2017/8/14.
 */
@Mapper
public interface SwitchMapper {
    @Insert("insert into res_device_switch(device_id, purpose, manage_ip, host_name, interface_num, g40_num, module_num, create_user, create_date, update_user, update_date)"
            + " values(#{deviceId},#{purpose},#{manageIp},#{hostName},#{interfaceNum},#{g40Num},#{moduleNum},#{createUser},#{createDate},#{updateUser},#{updateDate})")
    int insertSwitch(DeviceSwitch deviceSwitch);
    @Update("update res_device_switch set interface_num = #{interfaceNum},g40_num=#{g40Num},module_num =#{moduleNum},update_user =#{updateUser}," +
            "update_date =#{updateDate},purpose =#{purpose},manage_ip=#{manageIp},host_name=#{hostName} where device_id =#{deviceId}")
    int updateSwitch(DeviceSwitch deviceSwitch);

	@Update("update res_device_switch set interface_num = #{interfaceNum},g40_num=#{g40Num},module_num =#{moduleNum},update_user =#{updateUser}," +
			"update_date =#{updateDate} where device_id =#{deviceId}")
	int updateSwitchBase(DeviceSwitch deviceSwitch);
	@Update("update res_device_switch set update_user =#{updateUser},purpose =#{purpose},manage_ip=#{manageIp},host_name=#{hostName}," +
			"update_date =#{updateDate} where device_id =#{deviceId}")
	int updateSwitchManage(DeviceSwitch deviceSwitch);

	/*删除*/
	@Delete(value = "delete from res_device_switch WHERE device_id = #{0}")
	public int deleteDeviceSwitch(Long deviceId);
    @Select("SELECT CONCAT(device_id,'') as device_id, purpose, manage_ip, host_name, interface_num, g40_num, module_num "
			+ "FROM res_device_switch where device_id = #{deviceId}")
	@Results({
		@Result(column="device_id",property="deviceId"),@Result(column="purpose",property="purpose"),
		@Result(column="manage_ip",property="manageIp"),@Result(column="host_name",property="hostName"),
		@Result(column="interface_num",property="interfaceNum"),@Result(column="g40_num",property="g40Num"),
		@Result(column="module_num",property="moduleNum")})
	List<JSONObject> getDeviceSwitchById(Long deviceId);//根据设备id查询设备交换机信息
	@Select("SELECT * FROM res_device_switch where device_id = #{deviceId}")
	@Results({
			@Result(column="device_id",property="deviceId"),@Result(column="purpose",property="purpose"),
			@Result(column="manage_ip",property="manageIp"),@Result(column="host_name",property="hostName"),
			@Result(column="interface_num",property="interfaceNum"),@Result(column="g40_num",property="g40Num"),
			@Result(column="module_num",property="moduleNum"),@Result(column="create_user",property="createUser"),
			@Result(column="create_date",property="createDate"),@Result(column="update_user",property="updateUser"),
			@Result(column="update_date",property="updateDate")})
	DeviceSwitch getDeviceSwitchByDeviceId(Long deviceId);//根据设备id查询设备交换机信息
	
	
	//根据设备snNum查询设备交换机信息
	@Select("select a.device_id,a.sn_num,a.room_name,a.cabinet_code,a.start_num,a.end_num,b.brand_name,b.model_name,b.eqpt_spec,"
			+ "f_get_dict('eqpt_state',b.state) as state,c.interface_num,c.g40_num,c.module_num,c.purpose,c.manage_ip,c.host_name from "
			+ "res_device_location a,res_device_base b,res_device_switch c where a.device_id=b.device_id and "
			+ "b.device_id=c.device_id and if(#{0} is null,1=1,a.sn_num=#{0})")	
	@Results({
		@Result(column="device_id",property="deviceId"),@Result(column="sn_num",property="snNum"),
		@Result(column="room_name",property="roomName"),@Result(column="cabinet_code",property="cabinetCode"),
		@Result(column="start_num",property="startNum"),@Result(column="end_num",property="endNum"),		
		@Result(column="brand_name",property="brandName"),@Result(column="eqpt_spec",property="eqptSpec"),
		@Result(column="state",property="state"),@Result(column="interface_num",property="interfaceNum"),
		@Result(column="g40_num",property="g40Num"),@Result(column="module_num",property="moduleNum"),		
		@Result(column="purpose",property="purpose"),@Result(column="manage_ip",property="manageIp"),		
		@Result(column="model_name",property="modelName"),@Result(column="host_name",property="hostName")})
	List<ExportSwitchInfo> exportSwitchInfos(String snNum);
}
